<?php
namespace app\Index\controller;
use think\Controller;
use think\Request;
class Base extends Controller
{
    public function _initialize(){
        //网站配置项
        $this->getConf();
        //新闻资讯和养卡攻略
        $this->getArticles();
        //电脑端轮播图
        $this->getPcBanner();
        //手机端轮播图
        $this->getWapBanner();
        //友情链接
        $this->getLinks();
        //内页信息
        $this->getOther();

        $request = Request::instance();
        //获取当前控制器名称
        $con = $request->controller();
        //获取当前控制器方法名称
        $action = $request->action();
        $this->assign(array(
            'con'     =>$con,
            'action'  =>$action
        ));
    }

    //获取电脑端轮播图
    public function getPcBanner(){
        $banner = new \app\index\model\Banner();
        $banners = $banner->where(array('rec'=>1,'ispc'=>1))->order('sort desc')->limit(6)->select();
        $this->assign('pcbanners',$banners);
    }

    //获取手机端轮播图
    public function getWapBanner(){
        $banner = new \app\index\model\Banner();
        $banners = $banner->where(array('rec'=>1,'ispc'=>0))->order('sort desc')->limit(6)->select();
        $this->assign('wapbanners',$banners);
    }

    //获取新闻资讯和养卡攻略
    public function getArticles(){
        //获取新闻资讯
        $xwzx = db('article')->where(array('cateid'=>1))->order('time desc')->limit(4)->select();
        //获取养卡攻略
        $ykgl = db('article')->where(array('cateid'=>2))->order('time desc')->limit(4)->select();
//        dump($xwzxs[0]);die;
        $this->assign(array(
            'xwzx'  =>$xwzx,
            'ykgl'  =>$ykgl
        ));
    }

    //获取网站配置项
    public function getConf(){
        $conf = new \app\index\model\Conf();
        $_confres = $conf->getAllConf();//dump($_confres);die;
        $confres = array();
        foreach ($_confres as $k => $v) {
            $confres[$v['enname']] = $v['value'];
        }
        $this->assign('confres',$confres);
    }

    //获取友情链接
    public function getLinks(){
        $linkArr = db('link')->order('sort desc')->select();
        $this->assign('linkArr',$linkArr);
    }

    //获取当前位置
    public function getPos($cateid){
        $cate = new \app\index\model\Cate();
        $posArr = $cate->getparents($cateid);
        $this->assign('posArr',$posArr);
    }

    //获取当前位置
    public function getOther(){
//        $other = new \app\index\model\Other();
//        $others = $other->select();
//        $others = db('other')->select();
//        dump($others[0]);die;
//        $this->assign('others',$others);
    }
}
